package com.zzc.controller;

import com.zzc.domain.ProductInfor;
import com.zzc.serviceImpl.ProductServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {

    @Autowired
    ProductServiceImp productServiceImp;

    @RequestMapping("/getproductinfor")
    public String getProductInfor(){
        return productServiceImp.getProductInfor();
    }

    @RequestMapping("/getproductimg/{productName}")
    public String getProductImg(@PathVariable("productName") String name){
        return productServiceImp.getProductImg(name);
    }

    @RequestMapping("/getproductdetail/{productName}")
    public String getProductDetail(@PathVariable("productName") String name){
        return productServiceImp.getProductDetail(name);
    }

    @RequestMapping("/getcategory")
    public String getCategory(){
        return productServiceImp.getCategory();
    }

    @RequestMapping("/addorder/{userId}/{productName}/{unitPrice}/{num}/{total}")
    public void addOrder(@PathVariable("userId") String userId,@PathVariable("productName") String productName,
                         @PathVariable("unitPrice") String unitPrice,
                         @PathVariable("num") String num,@PathVariable("total") String total){
        String cover = productServiceImp.getProductInforByName(productName);
        productServiceImp.addOrder(userId,productName,cover,unitPrice,num,total);
    }

    @RequestMapping("/getorder/{userId}")
    public String getOrder(@PathVariable("userId") String userId){
        return productServiceImp.getOrder(userId);
    }

    @RequestMapping("/deleteorder/{userId}/{name}")
    public void deleteOrder(@PathVariable("userId") String userId,@PathVariable("name") String name){
        productServiceImp.deleteOrder(userId, name);
    }
}
